package com.algorithm.dp;

/**
 * 斐波那契
 *
 * @author Amadeus
 * @date 2023/10/20
 */
public class fibonacci {

    public static int fib(int n) {
        if (n < 2) {
            return n;
        }
        int i = 0;
        int j = 1;
        while (n-- > 0) {
            // i变成i+j. j变成原先i的值
            i += j;
            j = i - j;
        }
        return i;
    }

    public static void main(String[] args) {
        int fib = fib(6);
        System.out.println(fib);
    }

}
